package cn.zhiyong.pr.main;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import com.melloware.jintellitype.HotkeyListener;
import com.melloware.jintellitype.JIntellitype;


public class HotKey implements HotkeyListener {
	static final int hot_key=1;
	private MainController controller;
	
	public HotKey(MainController controller) {
		this.controller=controller;
	}

	@Override
	public void onHotKey(int key) {
		if (hot_key==key) {
			controller.switchView();
		}
		
	}
	
	public void initKey() {
		String HOT_KEY=HotKey.getPropertyFile().getProperty("hotkey");
		JIntellitype.getInstance().registerHotKey(hot_key, HOT_KEY);
		JIntellitype.getInstance().addHotKeyListener(this);
	}
	
	public void destroyKey() {
		JIntellitype.getInstance().unregisterHotKey(hot_key);
		JIntellitype.getInstance().cleanUp();
	}
	
	public static Properties getPropertyFile() {
		Properties property=null;
		String propertyFilePath=System.getProperty("user.dir")+"\\"+"hotKey.properties";
		File propertyFile=new File(propertyFilePath);
		property=new Properties();
		try {
			FileInputStream fis=new FileInputStream(propertyFile);
			property.load(fis);
			fis.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return property;
	}
}
